import 'package:mall/constant/app_parameters.dart';
import 'package:mall/constant/app_strings.dart';
import 'package:mall/constant/app_urls.dart';
import 'package:mall/modules/model/project_selection_detail_entity.dart';
import 'package:mall/modules/model/related_project_selection_entity.dart';
import 'package:mall/utils/net/http_util.dart';

class ProjectSelectionService {
  //项目详情
  static Future<ProjectSelectionDetailEntity> projectSelectionDetail(
    int id,
  ) async {
    var parameters = {AppParameters.ID: id};
    var response = await HttpUtil.instance.get(AppUrls.PROJECT_SELECTION_DETAIL, parameters: parameters);

    if (response[AppStrings.DATA] == null) {
      throw Exception(AppStrings.SERVER_EXCEPTION);
    }
    ProjectSelectionDetailEntity projectSelectionDetailEntity =
        ProjectSelectionDetailEntity.fromJson(response[AppStrings.DATA]);
    return projectSelectionDetailEntity;
  }

  // Future<JsonResult<ProjectSelectionDetailEntity>> projectSelectionDetail(
  //     Map<String, dynamic> parameters) async {
  //   JsonResult<ProjectSelectionDetailEntity> jsonResult =
  //       JsonResult<ProjectSelectionDetailEntity>();
  //   try {
  //     var response = await HttpUtil.instance
  //         .get(AppUrls.PROJECT_SELECTION_DETAIL, parameters: parameters);
  //     if (response[AppStrings.ERR_NO] == 0 &&
  //         response[AppStrings.DATA] != null) {
  //       ProjectSelectionDetailEntity projectSelectionDetailEntity =
  //           ProjectSelectionDetailEntity.fromJson(response[AppStrings.DATA]);
  //       jsonResult.isSuccess = true;
  //       jsonResult.data = projectSelectionDetailEntity;
  //     } else {
  //       jsonResult.isSuccess = false;
  //       jsonResult.message = response[AppStrings.ERR_MSG] != null
  //           ? response[AppStrings.ERR_MSG]
  //           : AppStrings.SERVER_EXCEPTION;
  //     }
  //   } catch (e) {
  //     jsonResult.isSuccess = false;
  //     jsonResult.message = AppStrings.SERVER_EXCEPTION;
  //   }
  //   return jsonResult;
  // }

  // Future<JsonResult<RelatedProjectSelectionEntity>> projectSelectionRecommend(Map<String, dynamic> parameters) async {
  //   JsonResult<RelatedProjectSelectionEntity> jsonResult = JsonResult<RelatedProjectSelectionEntity>();
  //   try {
  //     var response = await HttpUtil.instance.get(AppUrls.PROJECT_SELECTION_RECOMMEND, parameters: parameters);
  //     if (response[AppStrings.ERR_NO] == 0 && response[AppStrings.DATA] != null) {
  //       RelatedProjectSelectionEntity relatedProjectSelectionEntity =
  //           RelatedProjectSelectionEntity.fromJson(response[AppStrings.DATA]);
  //       jsonResult.isSuccess = true;
  //       jsonResult.data = relatedProjectSelectionEntity;
  //     } else {
  //       jsonResult.isSuccess = false;
  //       jsonResult.message =
  //           response[AppStrings.ERR_MSG] != null ? response[AppStrings.ERR_MSG] : AppStrings.SERVER_EXCEPTION;
  //     }
  //   } catch (e) {
  //     jsonResult.isSuccess = false;
  //     jsonResult.message = AppStrings.SERVER_EXCEPTION;
  //   }
  //   return jsonResult;
  // }
  // 获取推荐商品
// 获取推荐商品
  static Future<RelatedProjectSelectionEntity> fetchRecommendedGoods(int id) async {
    var parameters = {AppParameters.ID: id};
    var response = await HttpUtil.instance.get(AppUrls.PROJECT_SELECTION_RECOMMEND, parameters: parameters);
    if (response[AppStrings.DATA] == null) {
      throw Exception(AppStrings.SERVER_EXCEPTION);
    }
    return RelatedProjectSelectionEntity.fromJson(response[AppStrings.DATA]);
  }
}
